using System;
using CodeAngel.Domain.Framework;

namespace CodeAngel.Domain
{
	public partial class DataElement
	{
		#region SetDefaultPropertyValues

        /// <summary>
        /// Sets the properties of a new entity to its default values.
        /// </summary>
		internal override void SetDefaultPropertyValues()
		{
            this.SetFriendlyIdAsync();
            this.DataElementID = Guid.NewGuid();
            this.IsUpdateable = false;
            this.IncludeAllScalarTypeProperties = false;

            if (this.ParentEntity is AggregateDef)
            {
                this.AggregateDef = this.ParentEntity as AggregateDef;
                this.Name = "Root";
            }
            else if (this.ParentEntity is DataElement)
            {
                this.ParentDataElement = this.ParentEntity as DataElement;
                this.AggregateDef = this.ParentDataElement.AggregateDef;
            }
		}

		#endregion

        #region IsEntityOrCollectionType

        public bool IsEntityOrCollectionType
        {
            get
            {
                if (this.PropertyDef == null)
                {
                    return false;
                }
                else
                {
                    return this.PropertyDef.IsEntityOrCollectionType;
                }
            }
        }

        #endregion

        #region IsCollectionType

        public bool IsCollectionType
        {
            get
            {
                if (this.PropertyDef == null)
                {
                    return false;
                }
                else
                {
                    return this.PropertyDef.IsCollectionType;
                }
            }
        }

        #endregion

        #region IsScalarType
        
        public bool IsScalarType
        {
            get
            {
                if ((this.PropertyDef == null))
                {
                    return false;
                }
                else
                {
                    return this.PropertyDef.IsScalarType;
                }
            }
        }

        #endregion

        #region IsEntityType

        public bool IsEntityType
        {
            get
            {
                if ((this.PropertyDef == null))
                {
                    return false;
                }
                else
                {
                    return this.PropertyDef.IsEntityType;
                }
            }
        }

        #endregion

        #region PropertyDefChanged

        /// <summary>
        /// Handles when the PropertyDef changes.
        /// </summary>
        partial void PropertyDefChanged(PropertyDef previousValue, PropertyDef newValue)
        {
            if (newValue != null)
                this.Name = newValue.GetRelationConstantValue();
            else
                this.Name = "[null]";
        }

        #endregion

        #region ToString

        public override string ToString()
        {
            return this.Name;
        }

        #endregion
    }
}

